//
//  UIImage + Extension.swift
//  ZWWeibo
//
//  Created by flyiron on 16/4/27.
//  Copyright © 2016年 flyiron. All rights reserved.
//

import UIKit

extension UIImage{
    func scaleImageWithWidth(width:CGFloat) -> UIImage{
        if  self.size.width < width {
            return self
        }
        
        let height:CGFloat = width/self.size.width * self.size.height
        let rect = CGRect(x: 0, y: 0, width: width, height: height)
        UIGraphicsBeginImageContext(rect.size)
        self.drawInRect(rect)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        
        return image
    }
}
